class_name ComboAnimationStateComponent
extends StateComponent

var _animator: AnimatedSprite2D

var _animation_name: String

var _combo_count: int

var _combo_counter: int

var _combo_time: float

var _combo_timer_name: String


func _init(
	init_name: String,
	init_animator: AnimatedSprite2D,
	init_animation_name: String,
	init_combo_count: int,
	init_combo_time: float,
) -> void:
	super(init_name)
	_animator = init_animator
	_animation_name = init_animation_name
	_combo_count = init_combo_count
	_combo_counter = 0
	_combo_time = init_combo_time
	_combo_timer_name = _animation_name + "_" + "combo_timer"


func _on_setup() -> void:
	parent.owner.state_machine.add_component(BlackboardTimerStateComponent.new(_combo_timer_name, _combo_timer_name))


func _on_enter() -> void:
	if parent.owner.state_machine.blackboard[_combo_timer_name] > 0:
		_combo_counter = (_combo_counter + 1) % _combo_count
	else:
		_combo_counter = 0
	parent.owner.state_machine.blackboard[_combo_timer_name] = _combo_time
	_animator.play(_animation_name + str(_combo_counter + 1))


func _on_update(_delta: float) -> void:
	pass


func _on_exit() -> void:
	_animator.stop()
